package com.tanhua.duboo.server.controller;

import com.alibaba.dubbo.common.utils.Log;
import com.tanhua.common.utils.Cache;
import com.tanhua.duboo.server.service.TodayBestService;

import com.tanhua.duboo.server.vo.PageResult;
import com.tanhua.duboo.server.vo.RecommendUserQueryParam;
import com.tanhua.duboo.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;

    @GetMapping("todayBest")
    public ResponseEntity<TodayBest>queryTodayBest(@RequestHeader("Authorization") String token){

        try {
            TodayBest todayBest=   this.todayBestService.queryTodayBest(token);
            if (null !=todayBest){
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查询今日家人出错~ token"+token,e);
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 推荐用户列表
     * @param token
     * @param queryParam
     * @return
     */

    @GetMapping("recommendation")
    @Cache
    public ResponseEntity<PageResult> queryRecommendation(@RequestHeader("Authorization") String token,
                                                          RecommendUserQueryParam queryParam){
        try {
            PageResult pageResult = this.todayBestService.queryRecommendation(token, queryParam);
            if (null !=pageResult){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询推荐用户列表出错~ token"+token,e);
        }


        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
